package com.zhao.modleclass.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhao.modleclass.Helper.BitmapCircleTransformation;
import com.zhao.modleclass.R;
import com.zhao.modleclass.activity.SC_TeacherWebView;
import com.zhao.modleclass.bean.HomePageBean;

/**
 * Created by Administrator on 2016/12/6.
 */

public class HP_TeacherLeft_Adapter extends BaseAdapter {
    private HomePageBean homePageBean;
    private Context context;
    private LayoutInflater inflater;

    public HP_TeacherLeft_Adapter(Context context, HomePageBean homePageBean) {
        this.homePageBean = homePageBean;
        this.context = context;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public Object getItem(int position) {
        return homePageBean.getTeacher().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyTeacherHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_gv_hp, parent, false);
            holder = new MyTeacherHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyTeacherHolder) convertView.getTag();
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //找到点击的每一个item的网址
                String url="https://mrobot.pclady.com.cn/modern/s/teacher/techInfo.xsp?techId="+homePageBean.getTeacher().get(position).getTechId();
                String titleName=homePageBean.getTeacher().get(position).getTechNickName();
                Bundle bundle=new Bundle();
                bundle.putString("url",url);
                bundle.putString("name",titleName);
                //intent跳转
                Intent intent = new Intent(context, SC_TeacherWebView.class);
                intent.putExtra("url", bundle);
                intent.putExtra("name",bundle);
                //启动跳转
                context.startActivity(intent);
            }
        });
        Glide.with(context).load(homePageBean.getTeacher().get(position).getTechHeadUrl())
                .transform(new BitmapCircleTransformation(context))
                .into(holder.iv_gvdetail_icon);
        Glide.with(context).load(homePageBean.getTeacher().get(position).getTechIconUrl()).into(holder.iv_gvdetail_tag);
        holder.tv_gvdetail_name.setText(homePageBean.getTeacher().get(position).getTechNickName());
        holder.tv_gvdetail_position.setText(homePageBean.getTeacher().get(position).getTechJobName());
        holder.tv_gvdetail_fans.setText("粉丝 "+homePageBean.getTeacher().get(position).getFollowTotal());

        return convertView;
    }

    class MyTeacherHolder {
        private TextView tv_gvdetail_name, tv_gvdetail_position, tv_gvdetail_fans;
        private ImageView iv_gvdetail_icon, iv_gvdetail_tag;

        public MyTeacherHolder(View view) {
            iv_gvdetail_icon = (ImageView) view.findViewById(R.id.iv_gvdetail_icon);
            iv_gvdetail_tag = (ImageView) view.findViewById(R.id.iv_gvdetail_tag);
            tv_gvdetail_name = (TextView) view.findViewById(R.id.tv_gvdetail_name);
            tv_gvdetail_position = (TextView) view.findViewById(R.id.tv_gvdetail_position);
            tv_gvdetail_fans = (TextView) view.findViewById(R.id.tv_gvdetail_fans);
        }
    }
}
